package com.itheima.app.controller;

import com.itheima.app.interceptor.UserHolder;
import com.itheima.app.manager.SettingsManager;
import com.itheima.app.manager.UserManager;
import com.itheima.domain.db.Notification;
import com.itheima.vo.PageBeanVo;
import com.itheima.vo.SettingVo;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author Guanxing
 * @date 2021/9/19
 */
@RestController
public class SettingsController {

    @Autowired
    private SettingsManager settingsManager;

    //查询用户的陌生人问题
    @GetMapping("/users/settings")
    public SettingVo findSettings() {
        return settingsManager.findSettings();
    }

    @PostMapping("/users/questions")
    public void saveOrUpdateQuestion(@RequestBody Map map){
        //获得输入的文本数据
        String content = (String) map.get("content");

        //保存或者修改
        settingsManager.saveOrUpdateQuestion(content);
    }

    //保存或修改通知设置
    @PostMapping("/users/notifications/setting")
    public void saveOrUpdateNotifications(Notification notification){
        settingsManager.saveOrUpdateNotifications(notification);
    }

    //查询黑名单数据
    @GetMapping("/users/blacklist")
    public PageBeanVo findBlackList(
            @RequestParam(defaultValue = "1") Integer page ,
            @RequestParam(defaultValue = "5") Integer pageSize){

        return settingsManager.findBlackList(page,pageSize);
    }

    //删除黑名单用户信息
    @DeleteMapping("/users/blacklist/{blackUserId}")
    public void deleteBlackUser(@PathVariable("blackUserId") Long blackUserId){
        settingsManager.deleteBlackUser(blackUserId);
    }
}
